package org.qy.star_server.core;

import io.grpc.stub.StreamObserver;
import lombok.Data;
import org.qy.star_common.message.Message;
import org.qy.star_grpc.core_api.BrokerCoreApiProto;

import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author yinger
 * @description TODO
 * @date 2024/4/10 13:28
 **/
@Data
public class ConsumerEnv {
    // 消费者唯一标识
    private String consumerTag;
    // 订阅的队列
    private String username;
    private String virtualHostName;
    private String queueName;
    // autoAck
    private boolean autoAck = false;
    // 缓冲区
    private BlockingQueue<Message> messageBuffer = new LinkedBlockingQueue<>();
    // 流通道
    StreamObserver<BrokerCoreApiProto.Message> responseStreamChannel;
    // 状态
    private boolean online = false;

    public ConsumerEnv(String consumerTag, String username, String virtualHostName, String queueName, BlockingQueue<Message> messageBuffer, StreamObserver<BrokerCoreApiProto.Message> responseStreamChannel) {
        this.consumerTag = consumerTag;
        this.username = username;
        this.virtualHostName = virtualHostName;
        this.queueName = queueName;
        this.messageBuffer = messageBuffer;
        this.responseStreamChannel = responseStreamChannel;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        ConsumerEnv that = (ConsumerEnv) object;
        return Objects.equals(consumerTag, that.consumerTag);
    }

    @Override
    public int hashCode() {
        return Objects.hash(consumerTag);
    }
}
